/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package researchgrants.parts.GrantRequest.filters;

import researchgrants.parts.GrantRequest.*;
import java.util.Date;
import researchgrants.parts.GrantRequest.reminder.Reminder;

/**
 * Filter a GrantRequest if its deadline is between fromDate and toDate
 * Both fromDate and toDate can be null to signal no start or end date, respectively.
 * @author DOStudent1
 */
class GrantRequestFilterReminderDate implements GrantRequestFilter {

    private Date fromDate;
    private Date toDate;
    
    GrantRequestFilterReminderDate(Date fromDate, Date toDate) {
        this.fromDate=fromDate;
        this.toDate=toDate;
    }

    @Override
    public boolean isFiltered(GrantRequest grantRequest) {
        boolean isFiltered=false;
        Reminder reminder=grantRequest.getCurrentReminder();
        if (reminder==null) {
            isFiltered=true;
        } else {
            Date currentDate = reminder.getCurrentDate();
            if (currentDate==null) {
                isFiltered=true;
            } else {
                if (fromDate!=null) {
                    if (currentDate.before(fromDate)) {
                        isFiltered=true;
                    }
                }
                if (toDate!=null) {
                    if (currentDate.after(toDate)) {
                        isFiltered=true;
                    }
                }
            }
        }
        return(isFiltered);
    }
}
